
package net.zapasa.controller;

import java.util.Date;

import javax.annotation.Resource;

import net.zapasa.core.common.util.LogUtil;
import net.zapasa.modelo.service.PriceCompetitiveThread;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.broadleafcommerce.openadmin.web.controller.AdminAbstractController;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/" + UpdatePriceCompetitiveController.SECTION_KEY)
@Secured("PERMISSION_OTHER_DEFAULT")
public class UpdatePriceCompetitiveController extends AdminAbstractController {
	
	protected static final String SECTION_KEY = "update-price-competitive";
	    
    @Resource
    PriceCompetitiveThread priceCompetitiveThread;

    @RequestMapping(value = "", method = RequestMethod.GET)
    public String irInicio(Model model){
        setModelAttributes(model, SECTION_KEY);
        model.addAttribute("actualizando", "false");
        return "setting/update-price-competitive";
    }
    
    @RequestMapping(value = "", method = RequestMethod.POST, params="action")
    public String updatePrice(Model model, @RequestParam("action") final String action) {
        
    	LogUtil.info(this.getClass(), "entra en UpdatePriceCompetitiveController::updatePrice");
    	
    	setModelAttributes(model, SECTION_KEY);
        model.addAttribute("actualizando", "true");
        
        priceCompetitiveThread.setName("Test " + new Date().toString());
        priceCompetitiveThread.run();
        
        return "setting/update-price-competitive";
    }
    
}
